package com.yirui.bridge.udp.parser;

import com.yirui.bridge.udp.DataParser;
import io.netty.buffer.ByteBuf;

import java.util.Map;

/**
 * @author Dujie
 * @create 2021/11/25
 * @since 1.0.0
 */
public class Item0dParser implements DataParser {
    @Override
    public Object parse(ByteBuf buffer, int itemIndex, Map container) {
        int val = buffer.getByte(6);
        Object value = val;
        if(itemIndex == 0x03) {
            if (buffer.getByte(5) == 0xFF) {
                value = -val / 100.0f;
            } else {
                value = val / 100.0f;
            }
        }
        int channel = buffer.getByte(8);
        container.put( String.format("%02x_%s",itemIndex, channel+1), value);
        return null;
    }


    @Override
    public boolean isSingleValue() {
        return false;
    }
}
